/**
 * @Global.as
 *
 * @author sodaChen mail:sujun10#21cn.com
 * @version 1.0
 * <br>Copyright (C), 2013 asFrame.com
 * <br>This program is protected by copyright laws.
 * <br>Program Name:ASFrame
 * <br>Date:2016-5-29
 */
package com.asframe
{
	import com.asframe.collections.maps.HashMap;
	import com.asframe.pattern.observers.NoticeSubjects;
	
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.events.EventDispatcher;
	import com.asframe.lang.Singleton;

	/**
	 * 全局对象，用于存放全局使用的东西，主要是提供一些公共的数据，以及做防止垃圾回收的措施
	 * 游戏中最好不要直接在这里增加内容，这里维护的是属于框架通用的属性
	 * @author sodaChen
	 * Date:2016-5-29
	 */
	public final class Global extends Singleton
	{
		private static var instance:Global;
		public static function getInstance():Global
		{
			if(instance == null)
			{
				instance = Singleton.getInstanceOrCreate(Global);
			}
			return instance;
		}

		/** AS3的文档类 **/
		public var main:Sprite;
		/** AS3的舞台对象 **/
		public var stage:Stage;
		/** 全局事件派发器 **/
		public const dispatcher:EventDispatcher = new EventDispatcher();
		/** 全局主题订阅和派发 **/
		public const subjects:NoticeSubjects = new NoticeSubjects();
		/** 用于存放引用的公共集合 **/
		public const refMap:HashMap = new HashMap();
		/** 通用公共存放数据的集合 **/
		public const dataMap:HashMap = new HashMap();

		/**
		 *正常游戏帧频
		 */
		public static const FRAMERATE_NORMAL:int=30;

		public function Global()
		{
		}
		public function addRef(target:Object):void
		{
			refMap.put(target,target);
		}
		public function removeRef(target:Object):void
		{
			refMap.remove(target);
		}
		public function hasValue(key:*):Boolean
		{
			return dataMap.hasKey(key);
		}
		public function addValue(key:*, value:*):void
		{
			dataMap.put(key,value);
		}
		public function removeValue(key:*):*
		{
			return dataMap.remove(key);
		}
	}
}